FairCalendarOverviewTableFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 27
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A create 0 22 2
1
import { Inject, Injectable } from '@nestjs/common';
2
import { RowFactory } from 'src/Infrastructure/Tables/RowFactory';
3
import { Table } from 'src/Infrastructure/Tables';
4
import { ICalendarOverview } from 'src/Domain/FairCalendar/ICalendarOverview';
5
import { EventType } from 'src/Domain/FairCalendar/Event.entity';
6
import { ITranslator } from 'src/Infrastructure/Translations/ITranslator';
7
8
@Injectable()
9
export class FairCalendarOverviewTableFactory {
10
  constructor(
11
    private readonly rowFactory: RowFactory,
12
    @Inject('ITranslator')
13
    private readonly translator: ITranslator
14
  ) {}
15
16
  public create(overview: ICalendarOverview): Table {
17
    const columns = [];
18
    const rowBuilder = this.rowFactory.createBuilder();
19
20
    const eventTypes: string[] = Object.values(EventType);
21
    eventTypes.splice(-1, 0, 'leave');
22
23
    for (const type of eventTypes) {
24
      columns.push(
25
        this.translator.translate('faircalendar-type-option', { type })
26
      );
27
      rowBuilder.template('pages/faircalendar/_overview_badge.njk', {
28
        type,
29
        days: overview[type].days,
30
        details: overview[type].details
31
      });
32
    }
33
34
    const row = rowBuilder.build();
35
36
    return new Table(columns, [row]);
37
  }
38
}
39